home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / simula / books / books.lha / kirkerud / histofil.sim < prev    next >
Text File  |  1993-08-16  |  2KB  |  57 lines

  1. begin
  2.  
  3.   integer array count(5 : 200);
  4.   integer weight_group, least_weight_group,  greatest_weight_group,
  5.           asterisk_number, number_of_asterisks;
  6.   real    weight;
  7.  
  8.  
  9. ! Read the measurements one by one;
  10. ! write all measurements to the file weight.dta, and
  11. ! count how many observations there are in each weight group:   ;
  12.  
  13.   outtext("Please type the weights. "); outimage;
  14.   outtext("Remember to type -1 after the last one!"); outimage;
  15.   weight := inreal;
  16.   inspect new outfile("weight.dta") do
  17.     begin
  18.       open(blanks(10));
  19.       while  weight ge 0 do
  20.         begin
  21.           outfix(weight,3,10); outimage;
  22.           weight_group := entier(weight);
  23.           count(weight_group) := count(weight_group) + 1;
  24.           weight := inreal;
  25.         end;
  26.       close;
  27.     end of inspect outfile;
  28.  
  29.  
  30. ! Find the least and greatest weight-groups containing weights:  ;
  31.  
  32.   least_weight_group := 5;
  33.   while count(least_weight_group) = 0
  34.     do least_weight_group := least_weight_group + 1;
  35.   greatest_weight_group := 200;
  36.   while count(greatest_weight_group) = 0
  37.     do greatest_weight_group := greatest_weight_group  - 1;
  38.  
  39.  
  40. ! Write the histogram to file:   ;
  41.  
  42.   inspect new outfile("histo.res") do
  43.   begin
  44.     open(blanks(80));
  45.     outtext("Weight : Number of Students"); outimage;
  46.     for weight_group := least_weight_group step 1  until greatest_weight_group do
  47.       begin
  48.         outint(weight_group,6); outtext(" : ");
  49.         number_of_asterisks := count(weight_group);
  50.         for asterisk_number := 1 step 1 until  number_of_asterisks do outchar('*');
  51.         outimage;
  52.       end weight_group-repetition;
  53.     close;
  54.   end of inspect outfile;
  55.  
  56. end;
  57.